package com.example.freshmendemo;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.example.freshmendemo.adapter.MenuAdapter;
import com.example.freshmendemo.bean.LoginBean;
import com.google.gson.Gson;

import org.json.JSONObject;

public class MainActivity extends AppCompatActivity {

    private ListView menuListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
    }
    private void initView(){
        String[] menuArray = {"用户列表","校园新闻"};
        menuListView = (ListView) findViewById(R.id.menu_listview);
        MenuAdapter menuAdapter = new MenuAdapter(MainActivity.this,menuArray);
        menuListView.setAdapter(menuAdapter);
    }
    private void initData(){
        //创建网络请求队列
        RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);
        //发起网络请求
        String url = "http://106.12.30.77:8080/freshmenapp/classmate/list"; //发送请求的地址
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                System.out.println(jsonObject.toString());
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                System.out.println(volleyError);
                Toast.makeText(MainActivity.this, "网络请求失败", Toast.LENGTH_SHORT).show();
            }
        });

        requestQueue.add(jsonObjectRequest); //将请求内容放入队列中
    }

}
